//
//  MeetingBottomView.m
//  YUNWUMeetingDemo
//
//  Created by mac on 2019/7/15.
//  Copyright © 2019 DGL. All rights reserved.
//

#import "MeetingBottomView.h"
#import "MeetingBtn.h"


@interface MeetingBottomView ()

@property (nonatomic,strong) MeetingBtn *micBtn;//麦克风开关
@property (nonatomic,strong) MeetingBtn *cameraBtn;//摄像头开关
@property (nonatomic,strong) MeetingBtn *chatBtn;//聊天
@property (nonatomic,strong) MeetingBtn *excBtn;//转换摄像头
@property (nonatomic,strong) MeetingBtn *ratioBtn;//帧率
@property (nonatomic,strong) MeetingBtn *frameBtn;//分辨率

@property (nonatomic,strong) UIButton *exitBtn;//退出


@end

@implementation MeetingBottomView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark - public method
- (void)updateMic:(BOOL)selected {
    [_micBtn setSelected:selected];
}

- (void)updateCamera:(BOOL)selected {
    [_cameraBtn setSelected:selected];
}

#pragma mark -- Action
- (void)clickBtnForMBottomView:(UIButton *)sender{
    switch (sender.tag) {
        case MBottomViewBtnTypeMic: {
            sender.selected = !sender.selected;
            break;
        }
        case MBottomViewBtnTypeCamera: {
            sender.selected = !sender.selected;
            break;
        }
        case MBottomViewBtnTypeChat: {
            break;
        }
        case MBottomViewBtnTypeExCamera: {
            break;
        }
        case MBottomViewBtnTypeRatio: {
            break;
        }
        case MBottomViewBtnTypeExit: {
            break;
        }
        case MBottomViewBtnTypeFrame: {
            break;
        }
    }
    
    if (_response) {
        _response(self, sender);
    }
}

#pragma mark -- UI
- (void)setUI{
    _micBtn = [[MeetingBtn alloc]init];
    [_micBtn setImage:[UIImage imageNamed:@"meeting_mic_close"] forState:UIControlStateSelected];
    [_micBtn setImage:[UIImage imageNamed:@"meeting_mic_open"] forState:UIControlStateNormal];
    [_micBtn setTitle:@"关麦克风" forState:UIControlStateNormal];
    [_micBtn setTitle:@"开麦克风" forState:UIControlStateSelected];
    [_micBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_micBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    _micBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [_micBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _micBtn.tag = 1;
    [self addSubview:_micBtn];
    [_micBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.top.mas_equalTo(self.mas_top).offset(10);
        make.width.mas_equalTo(90);
        make.height.mas_equalTo(60);
    }];
    
    _cameraBtn = [[MeetingBtn alloc]init];
    [_cameraBtn setImage:[UIImage imageNamed:@"meeting_camera_close"] forState:UIControlStateSelected];
    [_cameraBtn setImage:[UIImage imageNamed:@"meeting_camera_open"] forState:UIControlStateNormal];
    [_cameraBtn setTitle:@"关摄像头" forState:UIControlStateNormal];
    [_cameraBtn setTitle:@"开摄像头" forState:UIControlStateSelected];
    [_cameraBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_cameraBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
    [_cameraBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [_cameraBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _cameraBtn.tag = 2;
    [self addSubview:_cameraBtn];
    [_cameraBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_micBtn.mas_right).offset(10);
        make.top.mas_equalTo(_micBtn.mas_top);
        make.width.mas_equalTo(100);
        make.height.mas_equalTo(60);
    }];
    
    _chatBtn = [[MeetingBtn alloc]init];
    [_chatBtn setImage:[UIImage imageNamed:@"meeting_chat"] forState:UIControlStateNormal];
    [_chatBtn setTitle:@"聊天" forState:UIControlStateNormal];
    [_chatBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_chatBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [_chatBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _chatBtn.tag = 3;
    [self addSubview:_chatBtn];
    [_chatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_cameraBtn.mas_right).offset(10);
        make.top.mas_equalTo(_cameraBtn.mas_top);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    
    _excBtn = [[MeetingBtn alloc]init];
    [_excBtn setImage:[UIImage imageNamed:@"meeting_camera_exchange"] forState:UIControlStateNormal];
    [_excBtn setTitle:@"切换摄像头" forState:UIControlStateNormal];
    [_excBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_excBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [_excBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _excBtn.tag = 4;
    [self addSubview:_excBtn];
    [_excBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_chatBtn.mas_right).offset(10);
        make.top.mas_equalTo(_chatBtn.mas_top);
        make.width.height.mas_equalTo(_cameraBtn);
    }];
    
    
    _ratioBtn = [[MeetingBtn alloc]init];
    [_ratioBtn setImage:[UIImage imageNamed:@"meeting_ratio"] forState:UIControlStateNormal];
    [_ratioBtn setTitle:@"分辨率" forState:UIControlStateNormal];
    [_ratioBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_ratioBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [_ratioBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _ratioBtn.tag = 5;
    [self addSubview:_ratioBtn];
    [_ratioBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left).offset(10);
        if (IsiPhoneX) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(-30);
        }else{
            make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
        }
        make.width.height.mas_equalTo(60);
    }];
    
    _exitBtn = [[UIButton alloc]init];
    [_exitBtn setBackgroundImage:[UIImage imageNamed:@"meeting_exit"] forState:UIControlStateNormal];
    [_exitBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _exitBtn.tag = 6;
    [self addSubview:_exitBtn];
    [_exitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.mas_centerX);
        make.bottom.mas_equalTo(_ratioBtn.mas_bottom);
        make.width.height.mas_equalTo(_ratioBtn);
    }];
    
    _frameBtn = [[MeetingBtn alloc]init];
    [_frameBtn setImage:[UIImage imageNamed:@"meeting_frame"] forState:UIControlStateNormal];
    [_frameBtn setTitle:@"帧率" forState:UIControlStateNormal];
    [_frameBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_frameBtn.titleLabel setFont:[UIFont systemFontOfSize:12]];
    [_frameBtn addTarget:self action:@selector(clickBtnForMBottomView:) forControlEvents:UIControlEventTouchUpInside];
    _frameBtn.tag = 7;
    [self addSubview:_frameBtn];
    [_frameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.mas_right).offset(-10);
        if (IsiPhoneX) {
            make.bottom.mas_equalTo(self.mas_bottom).offset(-30);
        }else{
            make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
        }
        make.width.height.mas_equalTo(_exitBtn);
    }];
    
}

@end
